import {baseApiUrl} from "@/util/publicConfig";

function request(url, method, data) {
  return new Promise((resolve, reject) => {
    // 参数,固定参数
    var datas = Object.assign(data, {})
    // uniapp的请求
    uni.request({
      url,
      data: Object.keys(datas).length > 0 ? datas : null,
      method: method,
      success: (res) => {
        resolve(res.data);
      },
      fail: (err) => {
        reject(err)
      }
    });
  })
}


// post请求
function requestPost({url, data,}) {
  return request(baseApiUrl + url, "POST", data || {})
}

// put请求
function requestPut({url, data,}) {
  return request(baseApiUrl + url, "PUT", data || {})
}

// get请求
function requestGet({url, data}) {
  return request(baseApiUrl + url, "GET", data || {})
}

export {
  requestPost, //post请求
  requestPut, //请求
  requestGet,
}
